// EOString.cs created with MonoDevelop
// User: awilliam at 1:24 PM 9/25/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;

namespace Whitemice.EOMono
{
  public class EOString : EOValue
  {
    protected string  val;
    
    public EOString() : base()
    {
      IsNull = true;
    }
    
    public EOString(string v) : base()
    {
      if (v == null) IsNull = true;
      this.Value = v;
    }
    
    public EOString(EOString v) : base()
    {
      this.Value = v.Value;
    }
    
    public override object Value
    {
      get 
      { 
        if (this.HasValue) return val; 
        throw new EONullValueException();
      }
      set 
      { 
        if (value == null)
        {
          this.IsNull = true;
        } else 
          {
            this.IsNull = false;
            val = value.ToString().Trim();
          }
      }
    } // end Value
    
    public static implicit operator string(EOString v)
    {
      return v.Value.ToString();
    }    
    
    public override string SQLValue()
    {
      if (IsNull) return "NULL";
      return string.Format("'{0}'", val.Replace("'", "''"));
    }    
  }
}
